#include <iostream>
#include <vector>

using namespace std;

int FindGreatestSumOfSubArray(vector<int> array) {
	if (array.size() == 0) return 0;
	int  result = array[0];

	for (int i = 0; i < array.size(); ++i)
	{
		int max = array[i],sum= (0);
		for (int j = i; j < array.size(); ++j)
		{
			sum += array[j];
			if (sum > max)
				max = sum;
		}
		if (max > result)
			result = max;
	}
	return result;
}



//int main()
//{
//	vector<int> v = { -2,-8,-1,-5,-9 };
//	int re = FindGreatestSumOfSubArray(v);
//	cout << re << endl;
//	system("pause");
//	return 0;
//}